package com.smcdd.cdb.dbo.cdb_dbo.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.entity.MainTenance;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Administrator on 2017/7/25 17:40
 * 邮箱：zhanghuaiha@gmail.com
 */

public class TainDialogAdapter extends RecyclerView.Adapter<TainDialogAdapter.ViewHolder> {
    private List<MainTenance> list;
    private String type;


    public TainDialogAdapter(String type){
        list = new ArrayList<>();
        this.type = type;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dialog_wifi,parent,false);
        return new TainDialogAdapter.ViewHolder(view);

    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        MainTenance scanResult = list.get(position);
        holder.ssid.setText("设备编号："+scanResult.getCharging_info_id().getAlias());
        int i = Integer.parseInt(scanResult.getOnline_time());
        int v1 = i / 60;
        int v2 = i % 60;
        if (type.equals("4")) {
            holder.time.setText("使用次数："+scanResult.getUse_num());
        }else {
            holder.time.setText("在线时长："+v1+"小时"+v2+"分钟");
        }

    }

    @Override
    public int getItemCount() {
        return list == null? 0 : list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        TextView ssid,time;

        public ViewHolder(View itemView) {
            super(itemView);
            ssid = (TextView) itemView.findViewById(R.id.id);
            time = (TextView) itemView.findViewById(R.id.time);
        }
    }


    public void addData(List<MainTenance> scan){
        if (list != null) {
            list.clear();
            list.addAll(scan);
        }
        notifyDataSetChanged();
    }

}